package com.shrct.businessprocess.purchase.impl;

import com.shrct.businessprocess.budget.RCBudget;
import com.shrct.businessprocess.budget.RCCostBreakDown;
import com.shrct.businessprocess.organization.RCEnterprise;
import com.shrct.businessprocess.product.RCAnonymousProductEntryDAO;
import com.shrct.businessprocess.product.RCProductEntry;
import com.shrct.businessprocess.product.RCProductSpecification;
import com.shrct.businessprocess.project.RCProject;
import com.shrct.businessprocess.purchase.RCAnonymousProductDeliverItem;
import com.shrct.businessprocess.purchase.RCBudgetContract;
import com.shrct.businessprocess.purchase.RCProductDeliver;
import com.shrct.businessprocess.purchase.impl.RCProductDeliverItemImpl;
import com.shrct.businessprocess.purchase.proxy.RCAnonymousProductDeliverItemProxy;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.Date;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.beans.factory.BeanFactory;

@Entity
@DiscriminatorValue("RCANONYMOUSPRODUCTDELIVERITEM_TYPE")
public class RCAnonymousProductDeliverItemImpl extends RCProductDeliverItemImpl implements RCAnonymousProductDeliverItem {
  public RCAnonymousProductDeliverItemImpl() {
    super();
  }
  
  public RCAnonymousProductDeliverItemImpl(final RCProductDeliver deliver) {
    super( deliver);
    
  }
  
  private Integer quantity;
  
  public Integer getQuantity() {
    return this.quantity;
  }
  
  public RCAnonymousProductDeliverItem setQuantity(final Integer quantity) {
    this.quantity = quantity;
    return this;			
    
  }
  
  public RCProductSpecification getProductSpec() {
    RCProductEntry _product = this.getProduct();
    RCProductSpecification _type = _product.getType();
    return _type;
  }
  
  public void performDeliver(final Date deliverDate) {
    BeanFactory _beanFactory = this.getBeanFactory();
    RCAnonymousProductEntryDAO _bean = _beanFactory.<RCAnonymousProductEntryDAO>getBean(RCAnonymousProductEntryDAO.class);
    RCProductDeliver _deliver = this.getDeliver();
    RCBudgetContract _contract = _deliver.getContract();
    RCBudget _budget = _contract.getBudget();
    RCCostBreakDown _cbd = _budget.getCbd();
    RCProject _project = _cbd.getProject();
    String _code = _project.getCode();
    RCProductEntry _product = this.getProduct();
    String _sid = _product.getSid();
    RCProductDeliver _deliver_1 = this.getDeliver();
    RCBudgetContract _contract_1 = _deliver_1.getContract();
    RCEnterprise _customer = _contract_1.getCustomer();
    _bean.transferAnonymousProduct(_code, _sid, this.quantity, _customer);
    RCProductEntry _product_1 = this.getProduct();
    RCProductDeliver _deliver_2 = this.getDeliver();
    String _location = _deliver_2.getLocation();
    _product_1.setLocation(_location);
    RCProductEntry _product_2 = this.getProduct();
    RCProductDeliver _deliver_3 = this.getDeliver();
    String _branch = _deliver_3.getBranch();
    _product_2.setBranch(_branch);
  }
  
  public void cancelDeliver() {
    UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException();
    throw _unsupportedOperationException;
  }
  
  public Integer getDeliveredQuantity() {
    return this.quantity;
  }
  
  public static RCAnonymousProductDeliverItem create(final RCProductDeliver deliver, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.purchase.RCAnonymousProductDeliverItem rCAnonymousProductDeliverItem = new com.shrct.businessprocess.purchase.impl.RCAnonymousProductDeliverItemImpl(
    	deliver
    );
    objectFactory.create(rCAnonymousProductDeliverItem);
    return rCAnonymousProductDeliverItem;			
    
  }
  
  public static RCAnonymousProductDeliverItem createRCAnonymousProductDeliverItemImpl(final RCProductDeliver deliver, final IObjectFactory objectFactory, final Procedure1<RCAnonymousProductDeliverItem> init) {
    com.shrct.businessprocess.purchase.RCAnonymousProductDeliverItem rCAnonymousProductDeliverItem = new com.shrct.businessprocess.purchase.impl.RCAnonymousProductDeliverItemImpl(
    	deliver
    );
    objectFactory.create(rCAnonymousProductDeliverItem);
    init.apply(rCAnonymousProductDeliverItem);
    
    return rCAnonymousProductDeliverItem;			
    
  }
  
  public RCAnonymousProductDeliverItemProxy toProxy() {
    com.shrct.businessprocess.purchase.proxy.RCAnonymousProductDeliverItemProxy proxy = new com.shrct.businessprocess.purchase.proxy.RCAnonymousProductDeliverItemProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
